package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author     ：zhangheng
 * @date       ：Created in 2024/9/12 17:21
 * @description：物模型数据
 * @modified By：
 * @version: 1.0
 */
@Service
public class DeviceDataServiceImpI implements DeviceDataService {
    @Autowired
    private DeviceDataMapper deviceDataMapper;

    @Override
    public PageResponse<DeviceDataVo> selectByPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        //前端传递是一个Long类型的毫秒值作为条件查询数据库需要转化日期类型
        Long startTime = deviceDataPageReqDto.getStartTime();
        Long endTime = deviceDataPageReqDto.getEndTime();
        deviceDataPageReqDto.setStartDate(ObjectUtil.isNotEmpty(startTime)?null: LocalDateTimeUtil.of(startTime));
        deviceDataPageReqDto.setEndDate(ObjectUtil.isNotEmpty(endTime)?null:LocalDateTimeUtil.of(endTime));
        //查询
        Page<DeviceDataVo>page =deviceDataMapper.selectByPage(deviceDataPageReqDto);
        return PageResponse.of(page,DeviceDataVo.class);
    }

}

